package com.ruoyi.iptv.channel.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iptv.channel.domain.IptvPublicChannel;
import com.ruoyi.iptv.channel.service.IIptvPublicChannelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公共内容Controller
 * 
 * @author 玉念聿辉
 * @date 2021-10-20
 */
@Controller
@RequestMapping("/channel/channel")
public class IptvPublicChannelController extends BaseController
{
    private String prefix = "channel/channel";

    @Autowired
    private IIptvPublicChannelService iptvPublicChannelService;

    @RequiresPermissions("channel:channel:view")
    @GetMapping()
    public String channel()
    {
        return prefix + "/channel";
    }

    /**
     * 查询公共内容列表
     */
    @RequiresPermissions("channel:channel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IptvPublicChannel iptvPublicChannel)
    {
        startPage();
        List<IptvPublicChannel> list = iptvPublicChannelService.selectIptvPublicChannelList(iptvPublicChannel);
        return getDataTable(list);
    }

    /**
     * 导出公共内容列表
     */
    @RequiresPermissions("channel:channel:export")
    @Log(title = "公共内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IptvPublicChannel iptvPublicChannel)
    {
        List<IptvPublicChannel> list = iptvPublicChannelService.selectIptvPublicChannelList(iptvPublicChannel);
        ExcelUtil<IptvPublicChannel> util = new ExcelUtil<IptvPublicChannel>(IptvPublicChannel.class);
        return util.exportExcel(list, "公共内容数据");
    }

    /**
     * 新增公共内容
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公共内容
     */
    @RequiresPermissions("channel:channel:add")
    @Log(title = "公共内容", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IptvPublicChannel iptvPublicChannel)
    {
        return toAjax(iptvPublicChannelService.insertIptvPublicChannel(iptvPublicChannel));
    }

    /**
     * 修改公共内容
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IptvPublicChannel iptvPublicChannel = iptvPublicChannelService.selectIptvPublicChannelById(id);
        mmap.put("iptvPublicChannel", iptvPublicChannel);
        return prefix + "/edit";
    }

    /**
     * 修改保存公共内容
     */
    @RequiresPermissions("channel:channel:edit")
    @Log(title = "公共内容", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IptvPublicChannel iptvPublicChannel)
    {
        return toAjax(iptvPublicChannelService.updateIptvPublicChannel(iptvPublicChannel));
    }

    /**
     * 删除公共内容
     */
    @RequiresPermissions("channel:channel:remove")
    @Log(title = "公共内容", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iptvPublicChannelService.deleteIptvPublicChannelByIds(ids));
    }
}
